import requests
import json
import pandas as pd


# 地理编码

def geocode(key,formatted_address,city=None,batch="false",sig=None,output="json",callback=None):
    """将详细的结构化地址转换为高德经纬度坐标"""
    geocode_url = "https://restapi.amap.com/v3/geocode/geo?parameters"
    params = {
        "key": key,
        "address": formatted_address,
        "city": city,
        "batch": batch,
        "sig": sig,
        "output": output,
        "callback": callback
    }
    r = requests.get(geocode_url, params=params)
    return r.json()


def driving(key,origin,destination,originid=None,destinationid=None,origintype=None,destinationtype=None,strategy=0,waypoints=None,avoidpolygons=None,avoidroad=None,province=None,number=None,cartype=0,ferry=0,roadaggregation="false",nosteps=0,sig=None,output="json",callback=None,extensions="base"):
    """规划以小客车、轿车通勤出行的方案，并且返回通勤方案的数据"""
    driving_url = "https://restapi.amap.com/v3/direction/driving?parameters"
    params = {
        "key": key,
        "origin": origin,
        "destination": destination,
        "originid": originid,
        "destinationid": destinationid,
        "origintype": origintype,
        "destinationtype": destinationtype,
        "strategy": strategy,
        "waypoints": waypoints,
        "avoidpolygons": avoidpolygons,
        "avoidroad": avoidroad,
        "province": province,
        "number": number,
        "cartype": cartype,
        "ferry": ferry,
        "roadaggregation": roadaggregation,
        "nosteps": nosteps,
        "sig": sig,
        "output": output,
        "callback": callback,
        "extensions": extensions
    }
    r = requests.get(driving_url, params=params)
    return r.json()
